export default{
  data() {
    return {
      prevID:'',

      modal10: false,
      pageSizeOpts: [5, 10, 15, 20],
      value: '',
      selectData:{
        ids:[]
      },
      total: 40,
      list: [],
      filter: {
        page: 0,
        rows: 10,
        name: ''
      }
    }
  },
  methods: {
    updata() {
      this.$http
        .post(`http://10.31.160.71:3000/${this.modules.type}/list`, this.filter)
        .then(response => {
          this.list = response.data.rows;
          this.total = response.data.total;
        });
    },
    changePage(page) {
      this.filter.page = page;
      this.updata();
    },
    changePageSize(pageSize) {
      this.filter.rows = pageSize;
      this.updata();
    },
    //查询
    search(){
      this.updata();
    },
    //删除多行
    selected(data){
      for(let i=0;i<data.length;i++){
        if(this.selectData.ids.indexOf(data[i]._id)===-1){
          this.selectData.ids.push(data[i]._id)
        }
      }
    },
    delectSelected(){
      this.selectData.ids=this.selectData.ids.toString();
      this.$http
        .post(`http://10.31.160.71:3000/${this.modules.type}/data/removes`, this.selectData)
        .then(response => {
          this.updata();
          this.selectData.ids=[]
          console.log('OK');
        });
     },


    handleSelectAll (status) {
      this.$refs.selection.selectAll(status);
  },
    //提示框
    success (nodesc) {
        this.$Notice.success({
            title: 'Success',
            desc: nodesc ? '' : ''
        });
    },
    error (nodesc) {
        this.$Notice.error({
            title: 'Error',
            desc: nodesc ? '' : ''
        });
    },
    //获取当前行的ID
    getID(data){
        this.prevID=data;
    },
    //删除
    remove(){
      this.$Modal.confirm({
          render: (h) => {
              return h('p', {

              },"Are you sure?")
          },
          onOk:()=>{
            let pid=this.prevID._id;
            this.$http
            .delete(`http://10.31.160.71:3000/${this.modules.type}/data/`+pid)
            .then(response => {
              this.updata();
              this.success(true);
            });
          }
      })

    }
  }
}
